<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <lay_head></lay_head>

    </div>
    <script>
        Vue.component("lay_head",{
            template:`
                <div>
                    <lay_child></lay_child>
                    <button @click="del">按钮</button>
                </div>
            `,
            methods:{
                del(){
                    // console.log("ok");
                    // this.$parent.$emit("test",{name:"Msea",age:"18"})

                }
            },
            components:{
                "lay_child":{
                    template:"<div>孙子<button @click='childTest'>自测试</button></div>",
                    methods: {
                        childTest(){
                            this.$root.$emit("test",{name:"Msea",age:"18"})
                            console.log(this.$root.name)
                        }
                    },
                }
            }
        })
        new Vue({
            el:"#app",
            data:{
                msg:"亲亲凄凄惨惨戚戚"
            },
            mounted(){
                this.$root.$on("test",(val)=>{
                    console.log(val)

                })
                this.$root.name="Msea"
            }
        })
    </script>
    
</body>
</html>